package com.ciquan.server.util.web;

import org.apache.commons.lang.StringUtils;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by kakarotto.li on 14-7-16.
 */
public class ParameterMap extends HashMap<String, Object>{

    public ParameterMap() {
        super();
        setPageNum(1);
        setStart(0);
    }

    public void setPageNum(int pageNum) {
        put("pageNum", pageNum);
    }

    public void setStart(int start) {
        put("start", start);
    }

    public String bulidSearchParameter() {
        StringBuffer buffer = new StringBuffer();
        String join_one = "&";
        String join_two = "=";

        for(Map.Entry<String, Object> entry : entrySet()) {

            if(StringUtils.equals(entry.getKey(), "pageNum")) {
                continue;
            }

            if(StringUtils.equals(entry.getKey(), "start")) {
                continue;
            }

            if(StringUtils.isNotBlank(entry.getKey()) && entry.getValue()!=null ){
                buffer.append(entry.getKey());
                buffer.append(join_two);
                buffer.append(entry.getValue());
                buffer.append(join_one);
            }
        }

        if(buffer.length()>0){
            buffer.deleteCharAt(buffer.length()-1);
        }

        return buffer.toString();
    }
}
